package edu.unipd.p2t.core;

import java.util.GregorianCalendar;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import edu.unipd.p2t.R;
import edu.unipd.p2t.db.DataManager;
import edu.unipd.p2t.db.Message;

public class Impostazioni extends Activity {
	private EditText mEditText;
    private Button mSendButton;
    private Activity me;
    private final String TAG="IM";
    private static final String PREFS_NAME = "Peer2TweetPreferences";


    
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    	Log.i(TAG,"Sono in Impostazioni");

        me=this;
        setContentView(R.layout.impostazioni);

        //ottengo componenti GUI
        mSendButton = (Button) findViewById(R.id.confirm);
    	mEditText = (EditText) findViewById(R.id.etuser);
    	
    	SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String user = settings.getString("UserName","User");
        
        mEditText.setText(user);
    	

        mSendButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	Log.i(TAG,"Hai scritto:"+mEditText.getText().toString());

            	SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putString("UserName", mEditText.getText().toString());

                 // Don't forget to commit your edits!!!
                editor.commit();

            	mEditText.setText("");
            	//Torno alla MainActivity
            	startActivity(new Intent(me,MainActivity.class));
            }
        });

	}
}
